﻿using System.Diagnostics;
using System.Linq;
using CCWP7.Model;
using Caliburn.Micro;

namespace CCWP7.CaliburnMicro
{
    public class ServerProjectsViewModel : ProjectsViewModelBase
    {
        public ServerProjectsViewModel(INavigationService navigationService)
            :
            base(navigationService)
        {
        }

        IServerReport _serverReport;
        public CCWP7.Model.IServerReport ServerReport
        {
            get
            {
                return _serverReport;
            }
            set
            {
                if (_serverReport != value)
                {
                    _serverReport = value;

                    RefreshItems();
                }
            }
        }

        public override void RefreshItems()
        {
            Items.Clear();

            if (_serverReport != null)
            {
                var array = _serverReport.Projects
                .Select(p => new ProjectViewModel(p))
                .ToArray();

                Items.AddRange(array);

                Debug.WriteLine("Items.Count=" + Items.Count);
            }

            Refresh();
        }
    }
}
